package com.edu.exam.entity.quality.workflow;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 审核结果实体类
 * 对应数据库表：audit_result
 *
 * 根据B-02-05试题审核流程子模块设计文档实现
 * 管理审核任务的执行结果，支持多种结果类型和评分配置。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "audit_result")
@Comment("审核结果表")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AuditResult {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 审核结果唯一标识符
     */
    @NotBlank(message = "审核结果ID不能为空")
    @Size(max = 50, message = "审核结果ID长度不能超过50个字符")
    @Column(name = "result_id", nullable = false, length = 50, unique = true)
    private String resultId;

    /**
     * 关联的审核任务ID
     */
    @NotBlank(message = "审核任务ID不能为空")
    @Size(max = 50, message = "审核任务ID长度不能超过50个字符")
    @Column(name = "task_id", nullable = false, length = 50)
    private String taskId;

    /**
     * 审核结果类型（1-通过，2-驳回，3-转审，4-取消）
     */
    @NotNull(message = "审核结果类型不能为空")
    @Column(name = "result_type", nullable = false)
    private Integer resultType;

    /**
     * 审核结果状态（DRAFT-草稿，SUBMITTED-已提交，APPROVED-已确认，REJECTED-已拒绝）
     */
    @NotBlank(message = "审核结果状态不能为空")
    @Size(max = 20, message = "审核结果状态长度不能超过20个字符")
    @Column(name = "result_status", nullable = false, length = 20)
    private String resultStatus;

    /**
     * 审核评分（0-100分）
     */
    @Column(name = "score", precision = 5, scale = 2)
    private BigDecimal score;

    /**
     * 评分权重
     */
    @Column(name = "weight", precision = 5, scale = 2)
    private BigDecimal weight;

    /**
     * 审核意见
     */
    @Column(name = "audit_opinion", columnDefinition = "TEXT")
    private String auditOpinion;

    /**
     * 审核说明
     */
    @Column(name = "audit_explanation", columnDefinition = "TEXT")
    private String auditExplanation;

    /**
     * 审核建议
     */
    @Column(name = "audit_suggestions", columnDefinition = "TEXT")
    private String auditSuggestions;

    /**
     * 审核人员ID
     */
    @Size(max = 50, message = "审核人员ID长度不能超过50个字符")
    @Column(name = "auditor_id", length = 50)
    private String auditorId;

    /**
     * 审核人员姓名
     */
    @Size(max = 100, message = "审核人员姓名长度不能超过100个字符")
    @Column(name = "auditor_name", length = 100)
    private String auditorName;

    /**
     * 提交时间
     */
    @NotNull(message = "提交时间不能为空")
    @Column(name = "submit_time", nullable = false)
    private LocalDateTime submitTime;

    /**
     * 审核时间
     */
    @Column(name = "audit_time")
    private LocalDateTime auditTime;

    /**
     * 审核标签（JSON格式）
     */
    @Column(name = "audit_tags", columnDefinition = "TEXT")
    private String auditTags;

    /**
     * 创建者ID
     */
    @Size(max = 50, message = "创建者ID长度不能超过50个字符")
    @Column(name = "created_by", nullable = false, length = 50)
    private String createdBy;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 软删除标识
     */
    @NotNull(message = "软删除标识不能为空")
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    /**
     * 更新人
     */
    @Size(max = 50, message = "更新人长度不能超过50个字符")
    @Column(name = "updated_by", nullable = false, length = 50)
    private String updatedBy;

}